#include "Translation.h"
#include <QXmlStreamWriter>

void Translation::dump(QXmlStreamWriter& writer)
{
	// Escribo el término siempre que no sea el original
	if (!_term.isEmpty() && (_name != "OriginalTerm")) {
			writer.writeStartElement("em");
			writer.writeAttribute("class", "term");
			writer.writeCharacters(_term);
			writer.writeEndElement(); // em
	}

	if (!_pos.isEmpty()) {
		if (_name != "OriginalTerm") {
			writer.writeCharacters(QString(" "));
		}
		writer.writeCharacters(QString("["));
		// Escribimos la posición
		writer.writeStartElement("em");
		writer.writeAttribute("class", "pos");
		writer.writeCharacters(_pos);
		writer.writeEndElement(); // em
		writer.writeCharacters(QString("]"));
	}

	if (!_sense.isEmpty()) {
		writer.writeCharacters(QString(" ("));
		writer.writeStartElement("em");
		writer.writeAttribute("class", "sense");
		writer.writeCharacters(_sense);
		writer.writeEndElement(); // em
		writer.writeCharacters(QString(")"));
	}

	if (!_usage.isEmpty()) {
		writer.writeCharacters(QString(" <"));
		writer.writeStartElement("em");
		writer.writeAttribute("class", "usage");
		writer.writeCharacters(_usage);
		writer.writeEndElement(); // em
		writer.writeCharacters(QString(">"));
	}

	// Si es el original y he escrito algo
	if ( (_name == "OriginalTerm") && (!_usage.isEmpty() || !_sense.isEmpty() || !_pos.isEmpty()) ) {
		writer.writeCharacters(": ");
	}
}

